package bluknite.util.network;

/**
 * This is the abstract superclass for all {@code TCPConnectionHandler}s
 * used in {@link TCPConnection}s.<br>
 * A {@code TCPConnectionHandler} is used to perform connection initiation
 * and connection ending processes as well as processing of data
 * recieved by a {@code TCPConnection} instance.<br>
 * <br>
 * All subclasses must implement the {@code connectionProcess()},
 * {@code processMessage()} and {@code disconnectionProcess()}
 * methods.
 * 
 * @author Siraj Ahmed
 */
public abstract class TCPConnectionHandler {
	/** An instance of the associated TCPConnection **/
	protected TCPConnection connection;
	
	/**
	 * Method that performs initiation procedures
	 * after actual connection has been established
	 * on the {@code TCPConnection}.
	 */
	public abstract void connectionProcess();
	
	/**
	 * Method used to process objects recieved by the
	 * {@code TCPConnection}.
	 * @param o the object to process.
	 */
	public abstract void processMessage(Object o);
	
	/**
	 * Method that performs disconnection procedures
	 * prior to actual disconnection of the
	 * {@code TCPConnection}.
	 */
	public abstract void disconnectionProcess();
	
	/**
	 * Sets the associated {@code TCPConnection}
	 * @param connection
	 */
	protected void setConnection(TCPConnection connection) {
		this.connection = connection;
	}
}
